import router from './router';
import {getToken} from '@/utils/auth'; // getToken from cookie

const whiteList = ['/login']; // no redirect whitelist

router.beforeEach((to, from, next) => {
  if (getToken()) { // determine if there has token
    /* has token*/
    next();
  } else {
    /* has no token*/
    if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单，直接进入
      next();
    } else {
      next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
    }
  }
});

router.afterEach(() => {

});
